package com.example.music.activity;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.music.R;
import com.example.music.db.RecentPlayDAO;
import com.example.music.model.Song;

import java.io.Serializable;
import java.util.List;

public class MusicDemoActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_music_demo);

        // 获取传递过来的歌曲信息
        String positionStr = getIntent().getStringExtra("position");
        List<Song> songList = (List<Song>) getIntent().getSerializableExtra("songList");

        if (positionStr != null && songList != null) {
            int position = Integer.parseInt(positionStr);
            if (position >= 0 && position < songList.size()) {
                Song song = songList.get(position);

                // 显示歌曲信息
                TextView textViewName = findViewById(R.id.textView_name);
                TextView textViewPosition = findViewById(R.id.textView_position);

                textViewName.setText(song.getTitle());
                textViewPosition.setText("Position: " + positionStr);

                // 添加到最近播放
                RecentPlayDAO recentDao = new RecentPlayDAO(this);
                recentDao.addRecentItem(song.getPath(), 0); // 0 表示歌曲类型
            } else {
                Log.e("MusicActivity", "Invalid position: " + positionStr);
            }
        } else {
            Log.e("MusicActivity", "Missing position or song list");
        }
    }
}